/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ClientsAndHotels.gui;

import java.util.Date;

import ClientsAndHotels.Utils;
import ClientsAndHotels.types.ClientParams;

/**
 * 
 * @author Karex
 */
public class ClientFrame extends javax.swing.JDialog {

    private boolean cancelled;
    private Date date = Utils.createDate(new Date());

    public boolean isCancelled() {
        return cancelled;
    }

    /**
     * Creates new form ClientFrame
     */
    public ClientFrame() {
        initComponents();
        dateLabel.setText(Utils.formatDate(date));
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed"
    // desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        nameField = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        cityField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        minStarsField = new javax.swing.JSpinner();
        jLabel4 = new javax.swing.JLabel();
        maxStarsField = new javax.swing.JSpinner();
        jLabel5 = new javax.swing.JLabel();
        roomForField = new javax.swing.JSpinner();
        jLabel6 = new javax.swing.JLabel();
        priceField = new javax.swing.JTextField();
        confirmClientButton = new javax.swing.JButton();
        cancelClientAdditionButton = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        daysSpinner = new javax.swing.JSpinner();
        dateLabel = new javax.swing.JLabel();
        changeDateButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Dodaj klienta");

        jLabel1.setText("Nazwa:");

        jLabel2.setText("Miasto:");

        jLabel3.setText("Min. gwiazdek:");

        minStarsField.setModel(new javax.swing.SpinnerNumberModel(3, 1, 5, 1));

        jLabel4.setText("Max. gwiazdek:");

        maxStarsField.setModel(new javax.swing.SpinnerNumberModel(3, 1, 5, 1));

        jLabel5.setText("Liczba osób:");

        roomForField.setModel(new javax.swing.SpinnerNumberModel(Integer
                .valueOf(2), Integer.valueOf(1), null, Integer.valueOf(1)));

        jLabel6.setText("Max. cena:");

        confirmClientButton.setText("Dodaj klienta");
        confirmClientButton
                .addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        confirmClientButtonActionPerformed(evt);
                    }
                });

        cancelClientAdditionButton.setText("Anuluj");
        cancelClientAdditionButton
                .addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        cancelClientAdditionButtonActionPerformed(evt);
                    }
                });

        jLabel7.setText("Data:");

        jLabel8.setText("Dni:");

        daysSpinner.setModel(new javax.swing.SpinnerNumberModel(1, 1, 7, 1));

        dateLabel.setText("data");

        changeDateButton.setText("Zmień");
        changeDateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                onChangeDateButtonClick(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
                getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(
                        layout.createSequentialGroup()
                                .addGroup(
                                        layout.createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(
                                                        layout.createSequentialGroup()
                                                                .addGap(72, 72,
                                                                        72)
                                                                .addComponent(
                                                                        confirmClientButton)
                                                                .addGap(18, 18,
                                                                        18)
                                                                .addComponent(
                                                                        cancelClientAdditionButton)
                                                                .addGap(0,
                                                                        170,
                                                                        Short.MAX_VALUE))
                                                .addGroup(
                                                        layout.createSequentialGroup()
                                                                .addContainerGap()
                                                                .addGroup(
                                                                        layout.createParallelGroup(
                                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                                .addGroup(
                                                                                        layout.createSequentialGroup()
                                                                                                .addGroup(
                                                                                                        layout.createParallelGroup(
                                                                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                                                                .addComponent(
                                                                                                                        jLabel4)
                                                                                                                .addComponent(
                                                                                                                        jLabel5)
                                                                                                                .addComponent(
                                                                                                                        jLabel6)
                                                                                                                .addComponent(
                                                                                                                        jLabel3)
                                                                                                                .addComponent(
                                                                                                                        jLabel2)
                                                                                                                .addComponent(
                                                                                                                        jLabel1))
                                                                                                .addGap(18,
                                                                                                        18,
                                                                                                        18)
                                                                                                .addGroup(
                                                                                                        layout.createParallelGroup(
                                                                                                                javax.swing.GroupLayout.Alignment.TRAILING)
                                                                                                                .addComponent(
                                                                                                                        cityField,
                                                                                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                                                                                .addComponent(
                                                                                                                        priceField,
                                                                                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                                                                                .addComponent(
                                                                                                                        roomForField,
                                                                                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                                                                                .addComponent(
                                                                                                                        maxStarsField,
                                                                                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                                                                                .addComponent(
                                                                                                                        minStarsField)
                                                                                                                .addComponent(
                                                                                                                        nameField)))
                                                                                .addGroup(
                                                                                        layout.createSequentialGroup()
                                                                                                .addGroup(
                                                                                                        layout.createParallelGroup(
                                                                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                                                                .addComponent(
                                                                                                                        jLabel7)
                                                                                                                .addComponent(
                                                                                                                        jLabel8))
                                                                                                .addGap(89,
                                                                                                        89,
                                                                                                        89)
                                                                                                .addGroup(
                                                                                                        layout.createParallelGroup(
                                                                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                                                                .addComponent(
                                                                                                                        daysSpinner)
                                                                                                                .addGroup(
                                                                                                                        layout.createSequentialGroup()
                                                                                                                                .addComponent(
                                                                                                                                        dateLabel)
                                                                                                                                .addPreferredGap(
                                                                                                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                                                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                                                        Short.MAX_VALUE)
                                                                                                                                .addComponent(
                                                                                                                                        changeDateButton)))))))
                                .addContainerGap()));
        layout.setVerticalGroup(layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(
                        layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(
                                        layout.createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel1)
                                                .addComponent(
                                                        nameField,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(
                                        layout.createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel2)
                                                .addComponent(
                                                        cityField,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(
                                        layout.createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel3)
                                                .addComponent(
                                                        minStarsField,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(
                                        layout.createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel4)
                                                .addComponent(
                                                        maxStarsField,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(
                                        layout.createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel5)
                                                .addComponent(
                                                        roomForField,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(
                                        layout.createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel6)
                                                .addComponent(
                                                        priceField,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(
                                        layout.createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(
                                                        jLabel7,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        21,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(dateLabel)
                                                .addComponent(changeDateButton))
                                .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(
                                        layout.createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(
                                                        daysSpinner,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel8))
                                .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                        48, Short.MAX_VALUE)
                                .addGroup(
                                        layout.createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(
                                                        confirmClientButton)
                                                .addComponent(
                                                        cancelClientAdditionButton))
                                .addContainerGap()));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void confirmClientButtonActionPerformed(
            java.awt.event.ActionEvent evt) {// GEN-FIRST:event_confirmClientButtonActionPerformed
        cancelled = false;
        setVisible(false);
    }// GEN-LAST:event_confirmClientButtonActionPerformed

    private void cancelClientAdditionButtonActionPerformed(
            java.awt.event.ActionEvent evt) {// GEN-FIRST:event_cancelClientAdditionButtonActionPerformed
        cancelled = true;
        setVisible(false);
    }// GEN-LAST:event_cancelClientAdditionButtonActionPerformed

    private void onChangeDateButtonClick(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_onChangeDateButtonClick
        DateChooser chooser = new DateChooser(this, true);
        chooser.setVisible(true);
        if (chooser.okClicked()) {
            date = Utils.createDate(chooser.getDate());
            dateLabel.setText(Utils.formatDate(date));
        }
    }// GEN-LAST:event_onChangeDateButtonClick

    /**
     * @param args
     *            the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        // <editor-fold defaultstate="collapsed"
        // desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase
         * /tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager
                    .getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ClientFrame.class.getName())
                    .log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ClientFrame.class.getName())
                    .log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ClientFrame.class.getName())
                    .log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ClientFrame.class.getName())
                    .log(java.util.logging.Level.SEVERE, null, ex);
        }
        // </editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new ClientFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelClientAdditionButton;
    private javax.swing.JButton changeDateButton;
    private javax.swing.JTextField cityField;
    private javax.swing.JButton confirmClientButton;
    private javax.swing.JLabel dateLabel;
    private javax.swing.JSpinner daysSpinner;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JSpinner maxStarsField;
    private javax.swing.JSpinner minStarsField;
    private javax.swing.JTextField nameField;
    private javax.swing.JTextField priceField;
    private javax.swing.JSpinner roomForField;

    // End of variables declaration//GEN-END:variables

    public String getClientName() {
        return nameField.getText();
    }

    public String getClientCity() {
        return cityField.getText();
    }

    public int getClientMinStars() {
        return (Integer) minStarsField.getValue();
    }

    public int getClientMaxStars() {
        return (Integer) maxStarsField.getValue();
    }

    public int getClientRoomFor() {
        return (Integer) roomForField.getValue();
    }

    public double getClientPrice() {
        return Double.parseDouble(priceField.getText());
    }

    public ClientParams getClient() {
        return new ClientParams(getClientName(), getClientCity(),
                getClientMinStars(), getClientMaxStars(), getClientRoomFor(),
                getClientPrice(), getDate(), getDays());
    }

    public int getDays() {
        return (int) daysSpinner.getValue();
    }

    public Date getDate() {
        return date;
    }

    public void reset() {
        cancelled = true;
        nameField.setText("");
        cityField.setText("");
        maxStarsField.setValue(new Integer(3));
        minStarsField.setValue(new Integer(3));
        roomForField.setValue(new Integer(2));
        priceField.setText("");
    }
}
